Plotly for Python is now entirely open source, free, and self-hosted

Learn more about why we've open sourced

Show Sidebar Hide Sidebar

WebGL Heatmaps in Python

How to make webGL based heatmaps in Python with Plotly.

WebGL based Heatmaps with Plotly

We start by importing the relevant modules:

In [1]:
import plotly.offline as py
py.init_notebook_mode()

import PIL
import urllib, cStringIO
import numpy as np

Downloading the image:

In [2]:
image_url = 'https://images.plot.ly/plotly-documentation/images/heatmap-galaxy.jpg'
f = cStringIO.StringIO(urllib.urlopen(image_url).read())
img = PIL.Image.open(f)
In [3]:
img
Out[3]:

Processing the image for generating heatmap:

In [4]:
arr = np.array(img)
z_data = []
In [5]:
for i in range(500):
    k = []
    for j in range(500):
        k.append(sum(arr[i][j]))
    z_data.append(k)

Generating the heatmap:

In [6]:
trace = dict(type='heatmapgl', z=z_data)
In [7]:
py.iplot([trace], validate=False)
Still need help?
Contact Us

For guaranteed 24 hour response turnarounds, upgrade to our Premium or Enterprise plans.